package main

import "fmt"

//通过鸡和狗都能跑的例子，用接口来实现
type animal interface {
	run(legs int) //1、这里需要注意，不要加上var
}

type dog struct {
	name string
}

func (d *dog) run(legs int) { //这里的接收器一般用指针*dog
	fmt.Printf("%s run with %d legs\n", d.name, legs)
}

type chicken struct {
	name string
}

func (c chicken) run(legs int) {
	fmt.Printf("%s run with %d legs\n", c.name, legs)
}

func main() {
	dog := &dog{"大黄"}
	ck := &chicken{"战斗鸡"}
	var i animal //申明接口
	i = dog
	i.run(4)
	i = ck
	i.run(2)
}
